//
//  MYStarView.m
//  JQLive
//
//  Created by Bruce on 2020/4/15.
//  Copyright © 2020 JQLive. All rights reserved.
//

#import "MYStarView.h"

@interface MYStarView ()

@property (nonatomic,copy) NSString *norImgName;
@property (nonatomic,copy) NSString *hightLightImgName;
@end

@implementation MYStarView

- (instancetype)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(0, 0, 120, 20);

    if(self = [super initWithFrame:frame])
    {
        self.norImgName = @"ic_star_nor";
        self.hightLightImgName = @"ic_star_hight_light";
        [self layout];
    }
    return self;
}

- (instancetype)initWithNorImgName:(NSString *_Nullable)nor
                 hightLightImgName:(NSString *_Nullable)hightLight
{
    CGRect frame = CGRectMake(0, 0, 120, 20);
    
    if(self = [super initWithFrame:frame])
    {
        self.norImgName = nor.length > 0 ? nor : @"ic_star_nor";
        self.hightLightImgName = hightLight.length > 0 ? hightLight : @"ic_star_hight_light";
        
        [self layout];
    }
    return self;
}

- (void)layout
{
    UIImageView *my_star1ImgView = [[UIImageView alloc] init];
    my_star1ImgView.image = [UIImage imageNamed:self.norImgName];
    my_star1ImgView.tag = 20000;
    [self addSubview:my_star1ImgView];
    
    UIImageView *my_star2ImgView = [[UIImageView alloc] init];
    my_star2ImgView.image = [UIImage imageNamed:self.norImgName];
    my_star2ImgView.tag = 20001;
    [self addSubview:my_star2ImgView];
    
    UIImageView *my_star3ImgView = [[UIImageView alloc] init];
    my_star3ImgView.image = [UIImage imageNamed:self.norImgName];
    my_star3ImgView.tag = 20002;
    [self addSubview:my_star3ImgView];
    
    UIImageView *my_star4ImgView = [[UIImageView alloc] init];
    my_star4ImgView.image = [UIImage imageNamed:self.norImgName];
    my_star4ImgView.tag = 20003;
    [self addSubview:my_star4ImgView];
    
    UIImageView *my_star5ImgView = [[UIImageView alloc] init];
    my_star5ImgView.image = [UIImage imageNamed:self.norImgName];
    my_star5ImgView.tag = 20004;
    [self addSubview:my_star5ImgView];
    
    [my_star1ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.centerY.equalTo(self);
    }];
    
    [my_star2ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(my_star1ImgView.mas_right).offset(1);
        make.centerY.equalTo(my_star1ImgView);
    }];
    
    [my_star3ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(my_star2ImgView.mas_right).offset(1);
        make.centerY.equalTo(my_star1ImgView);
    }];
    
    [my_star4ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(my_star3ImgView.mas_right).offset(1);
        make.centerY.equalTo(my_star1ImgView);
    }];
    
    [my_star5ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(my_star4ImgView.mas_right).offset(1);
        make.centerY.equalTo(my_star1ImgView);
    }];
}

- (void)setStarLevel:(NSInteger)starLevel
{
    for (int i = 0; i < starLevel; i++)
    {
        UIImageView *imgView = [self viewWithTag:i+20000];
        imgView.image = [UIImage imageNamed:self.hightLightImgName];
    }
}

- (void)setHeight:(NSInteger)height
{
    for (int i = 0; i < 5; i++)
    {
        UIImageView *imgView = [self viewWithTag:i+20000];
        
        [imgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.width.equalTo(@(height));
        }];
    }
}

@end
